package com.sharainy.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel(description = "返回结果")
public class RestResponse {
	 @ApiModelProperty("状态码 666:成功")
	    private int code;
	    @ApiModelProperty("消息")
	    private String message;
	    @ApiModelProperty("返回数据")
	    private Object data;

	    public RestResponse(){

	    }

	    public static RestResponse succuess(){
	        RestResponse restResponse = new RestResponse();
	        restResponse.setResultCode(ResultCode.SUCCESS);

	        return restResponse;
	    }

	    public static RestResponse succuess(Object data){
	        RestResponse restResponse = new RestResponse();
	        restResponse.setResultCode(ResultCode.SUCCESS);
	        restResponse.setData(data);

	        return restResponse;
	    }

	    public static RestResponse fail() {
	        RestResponse restResponse = new RestResponse();
	        restResponse.setResultCode(ResultCode.FAIL);

	        return restResponse;
	    }


	    public static RestResponse fail(ResultCode resultCode) {
	        RestResponse restResponse = new RestResponse();
	        restResponse.setResultCode(resultCode);

	        return restResponse;
	    }

	    public static RestResponse fail(String message) {
	        RestResponse restResponse = new RestResponse();
	        restResponse.setCode(ResultCode.FAIL.code());
	        restResponse.setMessage(message);

	        return restResponse;
	    }

	    public static RestResponse fail(Integer code, String message) {
	        RestResponse restResponse = new RestResponse();
	        restResponse.setCode(code);
	        restResponse.setMessage(message);

	        return restResponse;
	    }

	    public static RestResponse fail(ResultCode resultCode, Object data) {
	        RestResponse restResponse = new RestResponse();
	        restResponse.setResultCode(resultCode);
	        restResponse.setData(data);

	        return restResponse;
	    }

	    private void setResultCode(ResultCode resultCode){
	        this.code = resultCode.code();
	        this.message = resultCode.message();
	    }

	    public void setData(Object data){
	        this.data = data;
	    }

	    public Object getData(){
	        return data;
	    }

	    public int getCode() {
	        return code;
	    }

	    public void setCode(int code) {
	        this.code = code;
	    }

	    public String getMessage() {
	        return message;
	    }


		public void setMessage(String message){
	        this.message = message;
	    }

	    @Override
		public String toString() {
			return "RestResponse [code=" + code + ", message=" + message + ", data=" + data + "]";
		}
}
